<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>审核页面</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/Tools.js"></script>
</head>
<body>
<div id="container">
<form class="layui-form" id="atsSchemeForm">
    <input type="hidden" name="saId" id="saId" lay-verify="saId" autocomplete="off" class="layui-input">
    <input type="hidden" name="schemeType" id="schemeType" lay-verify="schemeType" autocomplete="off" class="layui-input">
    <input type="hidden" name="remark" id="remark" lay-verify="remark" autocomplete="off" class="layui-input">
    <div class="layui-form-item"></div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">方案名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="saName" id="saName" />
        </div>
    </div>
    <label class="layui-form-label"></label>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">申请理由</label>
        <div class="layui-input-block">
            <textarea  class="layui-textarea" name="applyForExp" id="applyForExp" ></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">申请人</label>
        <div class="layui-input-block">
            <input  class="layui-input" name="creater" id="creater" />
        </div>
    </div>

    <div class="layui-inline" style="margin-bottom: 20px">
        <label class="layui-form-label">选择专家</label>
        <div class="layui-input-inline">
            <select name="modules" lay-verify="required" id="expertId" lay-search="">


            </select>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">审核意见</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入审核意见" class="layui-textarea" name="auExp" id="auExp"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="button" class="layui-btn site-demo-active" lay-submit="" lay-filter="demo1" id="agreedBtn" value="同意"/>
            <input type="button" class="layui-btn layui-btn-danger site-demo-active" lay-submit="" lay-filter="demo2" id="notAgreedBtn" value="不同意"/>
        </div>
    </div>
</form>
</div>
<style>
    body { font-family:Verdana; margin:0 auto;}
    #container {margin: 0 auto; width:600px;}
</style>
<script>

    //取到上一个页面传过来的id
    var schemeId = getQueryString("id");
    $("#saId").val(schemeId);

    function renderForm() {
        layui.use('form', function() {
            var form = layui.form; //高版本建议把括号去掉，有的低版本，需要加()
            form.render("select");
        });
    }

    $(function(){
        var url1="../../AtsSchemeFsController/selectExpertBySaId";
        var data1={saId:schemeId};
        $.post(url1,data1,function (obj) {
            $("#saName").val(obj.saName);
            $("#saName").prop("disabled","disabled");
            $("#applyForExp").val(obj.applyForExp);
            $("#applyForExp").prop("disabled","disabled");
            $("#creater").val(obj.creater);
            $("#creater").prop("disabled","disabled");
        },"json");

    });

    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layedit=layui.layedit
            , laydate=layui.laydate
            , layer = layui.layer;


        //重新渲染select
        renderForm();


        var url2="../../AtsSchemeFsController/selectExpert";
        var data2={isva:1};
        $.post(url2,data2,function (obj) {
            var str="";
            $("#expertId").append("<option value='0'>直接选择或搜索选择</option>");
            $.each(obj,function (index,item) {
                str+="<option value='"+item.expertId+"'>"+item.expertName+"</option>";
            });
            $("#expertId").append(str);
            //重新渲染select
            form.render('select');

        },"json");


        //自定义验证规则
        form.verify({
            auExp: function(value){
                if(!value.length){
                    return '审核意见不能包含空格';
                }
            }
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');
            var url = "../../AtsSchemeFsController/UpdateAudit";

            //   20同意   21不同意
            data.field.auditState=20;
            data.field.expertId=$("#expertId").val();


            $.ajax({
                url: url,
                type: "post",
                data:data.field,
                dataType: "json",
                success: function (obj) {
                    if(obj.num==1){
                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 1000,
                        }, function () {
                            window.parent.location.reload();//刷新父页面
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg(obj.msg, {
                            icon: 2,
                            time: 1000,
                        }, function () {
                            window.parent.location.reload();//刷新父页面
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }

                }, error: function (e) {
                    alert('失败了');
                }

            });
        });

        //监听提交
        form.on('submit(demo2)', function (data) {
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');
            var url = "../../AtsSchemeFsController/UpdateAudit";
            //   20同意   21不同意
            data.field.auditState=21;

            $.ajax({
                url: url,
                type: "post",
                data:data.field,
                dataType: "json",
                success: function (obj) {
                    if(obj.num==1){
                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 1000,
                        }, function () {
                            window.parent.location.reload();//刷新父页面
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg(obj.msg, {
                            icon: 2,
                            time: 1000,
                        }, function () {
                            window.parent.location.reload();//刷新父页面
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }
                }, error: function (e) {
                    alert('失败了');
                }

            });
        });
    });

</script>

</body>
</html>